from django.conf.urls.defaults import *
from django.conf import settings
from django.contrib import admin
from lingcod.common.utils import get_mpa_class
from lingcod.common.utils import get_mpa_form

admin.autodiscover()

urlpatterns = patterns('',

    url(r'^$', 'lingcod.common.views.map', {'template_name': 'common/map_ext.html'}, name="map"),
    (r'^tests/', 'django.views.generic.simple.direct_to_template', {'template': 'common/tests.html', 'extra_context': {'api_key': settings.GOOGLE_API_KEY}}),
    (r'^layers/', include('lingcod.layers.urls')),
    (r'^studyregion/', include('lingcod.studyregion.urls')),
    (r'^faq/', include('lingcod.simplefaq.urls')),
    (r'^help/', include('lingcod.help.urls')),
    (r'^kml/', include('lingcod.kmlapp.urls')),
    (r'^manipulators/', include('lingcod.manipulators.urls')),
    # (r'^mpas/', include('lingcod.mpa.urls')),
    # (r'^arrays/', include('lingcod.array.urls')),
    url(r'^accounts/logout/$', 'django.contrib.auth.views.logout', {'next_page': settings.LOGIN_REDIRECT_URL},  name='auth_logout'),
    (r'^accounts/profile/', include('lingcod.user_profile.urls')),
    (r'^accounts/', include('lingcod.common.registration_backend.urls')),
    (r'^intersection/', include('lingcod.intersection.urls')),
    (r'^screencasts/', include('lingcod.screencasts.urls')),
    (r'^sharing/', include('lingcod.sharing.urls')),
    (r'^staticmap/', include('lingcod.staticmap.urls')),
    (r'^news/', include('lingcod.news.urls')),
    (r'^admin/', include(admin.site.urls)),
    url(r'^mpas/(?P<pk>\d+)/copy/$', 'copy', name="mpa-copy"),
)

# Useful for serving files when using the django dev server
urlpatterns += patterns('',
    (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True }),
)

MpaForm = get_mpa_form()

urlpatterns += patterns('lingcod.rest.views',
    url(r'^mpas/form/$', 'form_resources', {'form_class': MpaForm, 'create_title': 'Create a New Annotation'}, name='mpa_create_form'),
    url(r'^mpas/(?P<pk>\d+)/$', 'resource', {'form_class': MpaForm, 'template': 'mpa/show.html'}, name='mpa_resource'),
    url(r'^mpas/(?P<pk>\d+)/form/$', 'form_resources', {'form_class': MpaForm}, name='mpa_update_form'),
)

from lingcod.common.utils import get_array_form

urlpatterns += patterns('lingcod.array.views',
    url(r'^arrays/(?P<pk>\d+)/add_mpa/$', 'add_mpa', name='array-add-mpa'),
    url(r'^arrays/(?P<pk>\d+)/remove_mpa/$', 'remove_mpa', name='array-remove-mpa'),
    url(r'^arrays/(?P<pk>\d+)/copy/$', 'copy', name="array-copy"),
    url(r'^arrays/(?P<pk>\d+)/download/(?P<filenum>\d+)/$', 'download_supportfile', name="array-download"),
)

ArrayForm = get_array_form()

urlpatterns += patterns('lingcod.rest.views',
    url(r'^arrays/form/$', 'form_resources', {'form_class': ArrayForm, 'create_title': 'Create a New Folder'}, name='array_create_form'),
    url(r'^arrays/(?P<pk>\d+)/$', 'resource', {'form_class': ArrayForm, 'template': 'array/show.html'}, name='array_resource'),
    url(r'^arrays/(?P<pk>\d+)/form/$', 'form_resources', {'form_class': ArrayForm}, name='array_update_form'),
)
